﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KaoWuYouLibs.Common;
using KaoWuYouLibs.Model;
using System.Data.SqlClient;

namespace KaoWuYouLibs.Dal
{
    public class SubclassAccess
    {
        public List<SubclassModel> GetOwnedSubclasses(int SubjectID)
        {

            SqlConnection conn = new SqlConnection(Tools.ConnString);
            try
            {
                conn.Open();
                List<SubclassModel> re = new List<SubclassModel>();
                SqlCommand cmd = conn.CreateCommand();
                cmd.CommandText = "SELECT * FROM SubClass WHERE SubjectID = @SubjectID";
                cmd.Parameters.AddRange(new SqlParameter[] 
            { 
                new SqlParameter("@SubjectID", SubjectID) 
            });
                SqlDataReader sdr = cmd.ExecuteReader();
                while (sdr.Read())
                {
                    SubclassModel tmp = new SubclassModel()
                    {
                        SubclassID = (int)sdr["SubClassID"],
                        SubclassName = sdr["SubClassName"] as string

                    };
                    re.Add(tmp);
                }

                sdr.Close();
                return re;
            }
            catch (Exception ex)
            {
                return null;
            }
            finally
            {
                conn.Close();
            }
        }
    }
}
